package com.manlitech.manlichat.service;

import com.manlitech.manlichat.dao.ImUserFriendDao;
import com.manlitech.manlichat.dto.ImUserFriend;
import com.manlitech.manlichat.pojo.QueryParams;
import com.manlitech.manlichat.pojo.Result;
import com.manlitech.manlichat.util.ResultUtil;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.SQLReady;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.stereotype.Service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


@Service("imUserFriendService")
public class ImUserFriendService {
    @Autowired
    ImUserFriendDao imUserFriendDao;
    @Autowired
    SQLManager sqlManager;

    
    public Result queryPage(QueryParams params) {
        /**
        * sql中表名需要修改
        */
        StringBuffer sql = new StringBuffer("select * from imUserFriend where 1=1 ");

        SQLReady sqlReady = new SQLReady(sql.toString());

        PageQuery<ImUserFriend> pageQuery = new PageQuery<ImUserFriend>(params.getPage(),params.getLimit());
        PageQuery<ImUserFriend> query =sqlManager.execute(sqlReady,ImUserFriend.class,pageQuery);
        return ResultUtil.success(query.getList(),query.getTotalRow());
    }

    
    public Result queryAll() {
        List<ImUserFriend> list = imUserFriendDao.all();
        return ResultUtil.success(list);
    }

    
    public Result getById(Integer id) {
        ImUserFriend imUserFriend = imUserFriendDao.single(id);
        return ResultUtil.success(imUserFriend);
    }

    @Transactional
    public Result save(ImUserFriend imUserFriend) {
        imUserFriendDao.insert(imUserFriend);
        return ResultUtil.success();
    }

    @Transactional
    public Result updateById(ImUserFriend imUserFriend) {
        imUserFriendDao.updateById(imUserFriend);
        return ResultUtil.success();
    }

    @Transactional
	public Result updateTemplateById(ImUserFriend imUserFriend) {
        imUserFriendDao.updateTemplateById(imUserFriend);
        return ResultUtil.success();
    }

    @Transactional
    public Result removeByIds(List<Integer> ids) {
        for (Integer id:ids) {
            imUserFriendDao.deleteById(id);
        }
        return ResultUtil.success();
    }



}
